package xxy.com.yangproject.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import androidx.annotation.Nullable;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by xxy on 2018/8/4.
 *
 */

public class MyTextView2 extends View {

    private Paint paint;
    private int width;
    private int height;
    private Path path;
    private StaticLayout staticLayout;

    public MyTextView2(Context context) {
        super(context);
        init();
    }

    public MyTextView2(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MyTextView2(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {

        //文字
        String text1 = "我一定可以的，失败了，不要灰心丧气，因为每一次失败都是在让你知道如何避免失败从而走向成功。";
        TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        textPaint.setColor(Color.parseColor("#666666"));
        textPaint.setTextSize(42);
//        textPaint.setUnderlineText(true);
        staticLayout = new StaticLayout(text1, textPaint, 15, Layout.Alignment.ALIGN_NORMAL, 1, 0, true);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.save();
        canvas.translate(50, 100);
        staticLayout.draw(canvas);
        canvas.restore();
    }
}
